package org.fullhappy.bean.music;

import java.io.Serializable;
import java.util.ResourceBundle;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.fullhappy.bean.util.JsfUtil;
import org.fullhappy.business.MusicCategoryService;
import org.fullhappy.business.MusicSevice;
import org.fullhappy.business.SingerService;
import org.fullhappy.model.MusicModel;

@ManagedBean(name = "addMusicController")
@SessionScoped
public class AddMusicController implements Serializable {

    private MusicModel musicModel;
    
    private MusicSevice musicSevice ;
    private SingerService singerService ;
    private MusicCategoryService musicCategoryService;
    
    public AddMusicController() { 
        musicModel = new MusicModel();
        musicSevice = new MusicSevice();
        musicCategoryService = new MusicCategoryService();
        singerService = new SingerService();
        musicModel.setSelectSingerIdItems(singerService.getSelectItems());
        musicModel.setSelectCategoryIdItems(musicCategoryService.getSelectItems());
    }

    public void create() {
        try {
            musicSevice.create(musicModel);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/message").getString("MusicWasSuccessfullyCreated"));
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/message").getString("PersistenceErrorOccured"));
        }
    }

    public MusicModel getMusic() {
        return musicModel;
    }

    public void setMusic(MusicModel musicModel) {
        this.musicModel = musicModel;
    }
    
}
